<%--
  Created by IntelliJ IDEA.
  User: dqf
  Date: 2015/3/2
  Time: 16:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<div class="row">
    <!-- NEW WIDGET START -->
    <article class="col-sm-12 col-md-12 col-lg-12">
        <div class="jarviswidget well" id="wid-id-3"
             data-widget-colorbutton="false"
             data-widget-editbutton="false"
             data-widget-togglebutton="false"
             data-widget-deletebutton="false"
             data-widget-fullscreenbutton="false"
             data-widget-custombutton="false"
             data-widget-sortable="false">
            <!-- widget div-->
            <div>
                <div class="widget-body">
                    <a class="btn btn-default" id="linkman-re-common" href="javascript:void(0)">
                        <i class="fa fa-lg fa-mail-reply-all"></i>返回
                    </a>
                    <a class="btn btn-default pull-right pull-right-fix" id="btn-save-common" href="javascript:void(0);"><i class="fa fa-lg fa-download"></i> 保存</a>
                    <hr class="simple">
                    <form id="client" class="smart-form" novalidate="novalidate" action="" method="post">
                        <input type="hidden" name="keyId" id="keyId" value="<s:property value="client.id" />"/>
                        <header id="title" style="display: block;">
                            客户基本信息
                        </header>
                        <fieldset>
                            <%--<div class="row">--%>
                            <%--<label class="label col col-2">--%>
                            <%--客户编号--%>
                            <%--</label>--%>
                            <%--<section class="col col-5">--%>
                            <%--<label class="input state-disabled">--%>
                            <%--<input type="text" name="no" id="no" placeholder="" value="<s:property value="client.no"/>" disabled>--%>
                            <%--</label>--%>
                            <%--</section>--%>
                            <%--</div>--%>
                            <div class="row">
                                <label class="label col col-2">
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                    客户名称
                                </label>
                                <section class="col col-5">
                                    <label class="input">
                                        <input type="text" name="name" id="name" placeholder="请输入客户名称" value="<s:property value="client.name"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">
                                    客户简称
                                </label>
                                <section class="col col-5">
                                    <label class="input">
                                        <input type="text" name="subName" id="subName" placeholder="请输入客户简称" value="<s:property value="client.subName"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">
                                    发票抬头
                                </label>
                                <section class="col col-5">
                                    <label class="input">
                                        <input type="text" name="invoiceTitle" id="invoiceTitle" placeholder="请输入发票抬头" value="<s:property value="client.invoiceTitle"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                    客户性质
                                </label>
                                <section class="col col-5">
                                    <label class="input">
                                        <select class="form-control" name="dictId">
                                            <option value="">请选择</option>
                                            <s:iterator value="typesArrayList" id="list">
                                                <option  value="<s:property value="#list.id"/>" <s:property value="#list.selected"/> ><s:property value="#list.name"/></option>
                                            </s:iterator>
                                        </select>
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">
                                    所在地区
                                </label>
                                <div class="col col-7">
                                    <a class="btn btn-success btn-sm" id="areaselect_text" href="javascript:void(0);">请选择城市</a>
                                    <span id="areaselect_span">
                                        <input name="province" id="province" type="text" placeholder="省份" value="<s:property value="client.province"/>"/>
                                        <input name="city" id="city" type="text" placeholder="城市" value="<s:property value="client.city"/>"/>
                                        <input name="county" id="county" type="text" placeholder="县级" value="<s:property value="client.county"/>"/>
                                        <a class="btn btn-success btn-sm" id="areaselect_check" href="javascript:void(0);"><i class="fa fa-check"></i> </a>
                                        <a class="btn btn-warning btn-sm" id="areaselect_cancel" href="javascript:void(0);"><i class="fa fa-ban"></i> </a>
									 </span>
                                </div>
                            </div>
                            <div class="row">
                                <label class="label col col-2">客户情况说明</label>
                                <section class="col col-5">
                                    <label class="input">
                                        <input name="situtation" id="situtation" placeholder="请输入客户情况说明"
                                               type="text" value="<s:property value="client.situtation"/>">
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">备注</label>
                                <section class="col col-5">
                                    <label class="input">
                                        <input name="remark" id="remark" placeholder="请输入备注"
                                               type="text" value="<s:property value="client.remark"/>">
                                    </label>
                                </section>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </article>
</div>

<script>

    //返回视图
    $("#linkman-re-common").click(function(){
        loadURL("ajax!client.action",$('#content'));
    });
    //校验
    $("#client").validate({
        rules : {
            name : {
                required : true,
                remote:{
                    type:"POST",
                    url:"ajax-client!isUniqueByName.action",
                    data:{
                        keyId:$("#keyId").val(),
                        validatePro:"name",
                        newValue:function(){return $("#name").val();}
                    }
                }
            },
            dictId : {
                required : true
            },
            type : {
                required : true
            }
        },
        messages : {
            name : {
                required : '请输入客户名称',
                remote:'用户名已存在'
            },
            dictId : {
                required : '请选择客户性质'
            }
        },
        errorPlacement : function(error, element) {
            error.insertAfter(element.parent());
        }
    });

    $('.hasDatepicker').datetimepicker({
        format: 'yyyy-mm-dd',
        weekStart: 1,
        autoclose: true,
        todayBtn: 'linked',
        language: 'zh-CN',
        minView:2
    });
    //保存
    $("#btn-save-common").click(
            function(e) {
                var $valid = $("#client").valid();
                if(!$valid) return false;
                $.SmartMessageBox({
                    title : "提示：",
                    content : "确定提交吗？",
                    buttons : '[取消][确认]'
                }, function(ButtonPressed) {
                    if (ButtonPressed === "取消") {
                        e.preventDefault();
                        e.stopPropagation();
                        return;
                    }
                    if (ButtonPressed === "确认") {
                        $("#btn-save-common").attr("disabled", "disabled");
                        form_save("client","<%=path%>/com/ajax-client!save.action");
                        loadURL("ajax!client.action",$('#content'));
                    }
                });
            }
    );
</script>
<script type="text/javascript">
    //上传文件
    inputLoad({
        objId:"filename",
        entityName:"fileReplyId",
        sourceId:"fileId"
    });

    $(function(){
        var pdata= {
            keyId:$("#keyId").val(),
            flowName:"prostart"
        };
        multiDuty(pdata);
    });
    $("input[name=isDelegate]").unbind().bind("click",function(e){
        $("#agentName").val("");
        if($(this).prop("checked") && $(this).val() == "1"){
            $("#agentDiv").show();
        }else{
            $("#agentDiv").hide();
        }
    });

</script>

<script type="text/javascript">
    function loadCard(){
        area_save($("#province").val(),$("#city").val(),$("#county").val());
        $("a#areaselect_text").show();
    }
    loadCard();
    loadScript("../resource/com/js/data.js", loadSelect);
    function loadSelect(){
        loadScript("../resource/com/js/areaselect.js", loadLocation);
    }
    function loadLocation(){
        var locObj ;
        $("#areaselect_text").click(function(){
            $("#areaselect_span").show();
            locObj = new locationCard({
                ids: ['province', 'city', 'county']
            });
            locObj.init();
            $("#areaselect_text").hide();
        });
        $("#areaselect_span").hide();
        $("#areaselect_check").click(function(){

            if($("#province").val()!=null){
                area_save($("#province").val(),$("#city").val(),$("#county").val());
                $("#areaselect_span").hide();
                $("#areaselect_text").show();
                locObj.destoryCards();
            }else{
                $.smallBox({
                    title : "操作失败",
                    content : "<i class='fa fa-clock-o'></i> <i> 请选择地区，地区不能为空！</i>",
                    color : "#C46A69",
                    iconSmall : "fa fa-times fa-2x fadeInRight animated",
                    timeout : 6000
                });
                locObj.destoryCards();
            }
        })
        $("#areaselect_cancel").click(function(){

            $("#areaselect_span").hide();
            $("#areaselect_text").show();
            locObj.destoryCards();
        })
    }
    function area_save(p,city,county){
        $("a#areaselect_text").text(p+city+county);
        if(p == "") {
            $("a#areaselect_text").text("请选择地址");
        }
    }

    $(function(){
        $("input[name='name']").bind("keyup",function(){
            $("input[name='invoiceTitle']").val($("input[name='name']").val());
        });
    });
</script>